import axios from '@/util/axios';
import { orgNatureNameFun, orgOwnerShipTypeNameFun, certDeadlineNameFun, manageRelationShipNameFun, certTypeNameFun, relationShipNameFun } from '@/util/format';
const member = {
    namespaced: true,
    state: {
        name: 'member',
        memberDetail: [],
        fuMinMemberDetail: {}
    },

    // 更改数据
    mutations: {
        setMemberDetail(state: any, memberDetail:Array<object>) {
            state.memberDetail = memberDetail;
        },

        setFuMinMemberDetail(state: any, fuMinMemberDetail:object) {
            state.fuMinMemberDetail = fuMinMemberDetail;
        }
    },

    // 异步操作
    actions: {

        async loadPlatformDetail({ commit }: any, payload: object) {
            let res = await axios.post('hpxMemberReview/getHpxMemberReviewInfo', payload);
            commit('setMemberDetail', res.data);
            return res;
        },

        async loadFuMinDetail({ commit }: any, enterpriseId: String) {
            let res = await axios.get(`fBankMemberReview/getFBankMemberReviewInfo?fBankEnterpriseId=${enterpriseId}`);
            res.data.orgNatureName = orgNatureNameFun(res.data.orgNature)
            res.data.orgOwnerShipTypeName = orgOwnerShipTypeNameFun(res.data.orgOwnerShipType)
            res.data.certArray.forEach((i) => {
                i.certDeadlineName = certDeadlineNameFun(i.certDeadline)
            })
            res.data.manageArray.forEach((j) => {
                j.manageRelationShipName = manageRelationShipNameFun(j.relationShip)
                j.certDeadlineName = certDeadlineNameFun(j.certDeadline)
                j.certTypeName = certTypeNameFun(j.certType)
            })
            res.data.stockHolderArray.forEach((k) => {
                k.certTypeName = certTypeNameFun(k.certType)
                k.certDeadlineName = certDeadlineNameFun(k.certDeadline)
                k.relationShipName = relationShipNameFun(k.relationShip)
            })
            commit('setFuMinMemberDetail', res.data);
            return res;
        }
    },
    // 衍生属性
    getters: {

    }
}

export default member;